package com.coffee.ocean.endpoint;

import com.coffee.core.CoffeeResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

import java.time.Duration;
import java.util.ArrayList;
import java.util.List;

/**
 * @author songkui
 * @since 2024/8/9 9:54
 */
@RestController
@RequestMapping("/test")
@Slf4j
public class TestEndpoint {

    @GetMapping
    public Mono<CoffeeResponse<List<String>>> get(){
        List<String> list = new ArrayList<>(3);
        list.add("AAA");
        list.add("BBB");
        list.add("CCC");

        Flux<String> characterFlux = Flux
                .just("Garfield")
                .delayElements(Duration.ofMillis(5000)); // 每500毫秒发布⼀个数据
        characterFlux.subscribe(x -> log.info("xxxxxxxxxxx "+ x));

        log.info("yyyyyyyyyyyyyyyyyyyyyyyy");
        return Mono.just(CoffeeResponse.responseSuccess(list));
    }

}
